package com.tencent.trtc.apiexample;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.tencent.trtc.apiexample.ui.notifications.NotificationsFragment;

import static com.tencent.trtc.apiexample.LoginActivity.PATH;
import static com.tencent.trtc.apiexample.LoginActivity.USERNAME;
import static com.tencent.trtc.apiexample.LoginActivity.json;

public class AlterActivity extends AppCompatActivity {
    private EditText met_usertel;
    private EditText met_useremail;
    private Button mbtn_alter_confirm;

    private String alter_usertel="";
    private String alter_useremail="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alter);

        met_usertel=findViewById(R.id.et_usertel);
        met_useremail=findViewById(R.id.et_useremail);
        mbtn_alter_confirm=findViewById(R.id.btn_alter_confirm);

        mbtn_alter_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alter_usertel=met_usertel.getText().toString();
                alter_useremail=met_useremail.getText().toString();
                new Thread(new MyThread()).start();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    class MyThread implements Runnable {

        @Override
        public void run() {
            alter_useremail = met_useremail.getText().toString();
            alter_usertel = met_usertel.getText().toString();
            String path = PATH + "/update?username="+USERNAME+"&telephone="+alter_usertel+"&email="+alter_useremail;
            String result = WebServiceGet.executeHttpGet(path);
            if(result.equals("1")){
                json.put("telephone",alter_usertel);
                json.put("email",alter_useremail);
            }
            Intent intent = new Intent(AlterActivity.this, NavActivity.class);
            intent.putExtra("upresult",result);
            startActivity(intent);
        }
    }
}